//
//  NYMyVipHeaderView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyVipHeaderView.h"
@interface NYMyVipHeaderView ()

@property(nonatomic, strong) UIView *vipView;
@property(nonatomic, strong) QMUIGhostButton *headImgBtn;
@property(nonatomic, strong) TTTAttributedLabel *nickNamelabel;
@property(nonatomic, strong) TTTAttributedLabel *timeLabel;

@end
@implementation NYMyVipHeaderView
- (void)setVipModel:(NYMyVipModel *)vipModel
{
        _vipModel = vipModel;
        [self updateContent];
}
- (void)updateContent
{
        [self.headImgBtn sd_setImageWithURL:[NSURL URLWithString:NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.avatar)] forState:(UIControlStateNormal) placeholderImage:[UIImage pic_default_avatar]];
        NSString *nameStr = NOT_NULL_STRING(NYUserManager.nickname, @"匿名");
        self.nickNamelabel.text = NYUserManager.isLogin ? [NSString stringWithFormat:@"%@同学",nameStr] : @"注册/登录";
//        NSString *startTime = [AppUnit formatGMT8TimeMillisecond:self.vipModel.start_time.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];
        NSString *endTime = [AppUnit formatGMT8TimeMillisecond:self.vipModel.ent_time.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];
        self.timeLabel.text = [NSString stringWithFormat:@"您的年会员到期时间：%@",endTime];
}
- (void)setupView
{
        [super setupView];
        [self addSubview:self.bgImgView];
        [self addSubview:self.vipView];
        
        [self.bgImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self);
        }];
        [self.vipView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self).offset(__WGWidth(23));
                make.right.equalTo(self).offset(-__WGWidth(23));
                make.bottom.equalTo(self).offset(__WGHeight(27));
                make.height.mas_equalTo(__WGHeight(143));
        }];
        
        [self.vipView addSubview:self.headImgBtn];
        [self.vipView addSubview:self.nickNamelabel];
        [self.vipView addSubview:self.timeLabel];
//        [self.vipView addSubview:self.renewBtn];
        
        [self.headImgBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.vipView).offset(__WGWidth(17));
                make.top.equalTo(self.vipView).offset(__WGHeight(22));
                make.width.height.mas_equalTo(__WGHeight(41));
        }];
        [self.nickNamelabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.headImgBtn.mas_top).offset(__WGHeight(3));
                make.left.equalTo(self.headImgBtn.mas_right).offset(__WGWidth(11));
                make.right.lessThanOrEqualTo(self.vipView).offset(-__WGWidth(16));
        }];
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.nickNamelabel);
                make.top.equalTo(self.nickNamelabel.mas_bottom).offset(__WGHeight(7));
                make.right.lessThanOrEqualTo(self.vipView).offset(-__WGWidth(16));
        }];
//        [self.renewBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//                make.right.equalTo(self.vipView.mas_right).offset(-__WGWidth(15));
//                make.bottom.equalTo(self).offset(-__WGHeight(15));
//                make.width.mas_equalTo(__WGWidth(90));
//                make.height.mas_equalTo(__WGHeight(27));
//        }];
}

#pragma mark -
- (void)immediatelyARenewalButtonEvent:(id)sender {
        
        if (self.renewalBlock) self.renewalBlock();
}

- (UIImageView *)bgImgView
{
        if (_bgImgView == nil) {
                _bgImgView = [[UIImageView alloc] init];
                _bgImgView.backgroundColor = UIColorHex(0x3696FF);
                _bgImgView.image = [UIImage imageWithColor:UIColorHex(0x3696FF)];
                _bgImgView.contentMode = UIViewContentModeScaleToFill;
        }
        return _bgImgView;
}
- (UIView *)vipView
{
        if (_vipView == nil) {
                _vipView = [[UIView alloc] init];
                _vipView.backgroundColor = [UIColor jk_gradientFromColor:UIColorHex(0xD0B27C) toColor:UIColorHex(0xEED9AE) withHeight:143];
                _vipView.layer.cornerRadius = 5;
                _vipView.clipsToBounds = YES;
        }
        return _vipView;
}
//- (QMUIGhostButton *)renewBtn
//{
//        if (_renewBtn == nil) {
//                _renewBtn = [[QMUIGhostButton alloc] init];
//                _renewBtn.ghostColor = UIColorHex(0x836131);
//                _renewBtn.borderWidth = 1;
//                _renewBtn.clipsToBounds = YES;
//                [_renewBtn setTitle:@"充值牛币" forState:(UIControlStateNormal)];
//                [_renewBtn addTarget:self action:@selector(immediatelyARenewalButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
//        }
//        return _renewBtn;
//}
- (TTTAttributedLabel *)timeLabel
{
        if (_timeLabel == nil) {
                _timeLabel = [self createLabel];
                _timeLabel.font = WGSystem12Font;
        }
        return _timeLabel;
}
- (TTTAttributedLabel *)nickNamelabel
{
        if (_nickNamelabel == nil) {
                _nickNamelabel = [self createLabel];
        }
        return _nickNamelabel;
}
- (TTTAttributedLabel *)createLabel
{
        TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        label.font = WGSystem16Font;
        label.textColor = [UIColor whiteColor];
        return label;
}
- (QMUIGhostButton *)headImgBtn
{
        if (_headImgBtn == nil) {
                _headImgBtn = [[QMUIGhostButton alloc] init];
                _headImgBtn.ghostColor = [UIColor whiteColor];
                _headImgBtn.borderWidth = 2;
                _headImgBtn.clipsToBounds = YES;
        }
        return _headImgBtn;
}
@end
